// pages/news/comment.js
// 获取应用实例
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pagepoint: "",
        listApi: "",
        listObl: {},
        iPage: 1,
        iPages: 0,
        iPageSize: 10,
        listData: [],
        bCommity: false,
        listDataMoni:[
            {
                iID: 1,
                sNickName: "中级抬杠师",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样我就是我是颜色不i一样",
                iTime: 1647846222
            },{
                iID: 2,
                sNickName: "XR_128SJAL",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样", 
                iTime: 1647758251
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647585451
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647827869
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647827869
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647827869
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647827869
            },{
                iID: 3,
                sNickName: "CYRJ",
                sPic: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKdeGqXdB7va3OOVnVgQu4gMZhqfU5vrJiantDIZQiaZydsFTpx90Lv5hBBBGWC2uJOgwic6icPdxB0hg/132",
                sContent: "我就是我是颜色不i一样",
                iTime: 1647827869
            }
        ]
    },
    

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var _this = this;
        var pagepoint = options.pagepoint;//页面标识
        if (pagepoint != null && pagepoint != undefined) { //获取页面标识信息
            var api_common_news = app.globalData.api_common_news;
            _this.setData({ //更新页面标识
                pagepoint: pagepoint,
            })
            if (api_common_news.hasOwnProperty(pagepoint)) {
                //检测是否存在评论列表接口
                if(api_common_news[pagepoint]['sCommityListApi'] != "" && api_common_news[pagepoint]['sCommityListApi'] != undefined){
                    _this.setData({
                        bCommity: api_common_news[pagepoint]['bCommity']
                    })
                    var listObj = {};
                    listObj['iPage'] = _this.data.iPage;
                    listObj['iPageSize'] = _this.data.iPageSize;
                    console.log(api_common_news[pagepoint]['sCommityListPost'])
                    if(api_common_news[pagepoint]['sCommityListPost'] != ""){
                        listObj[api_common_news[pagepoint]['sCommityListPost']] = options.id;
                    }else{
                        listObj['iID'] = options.id;
                    }
                    
                    _this.setData({
                        listApi: api_common_news[pagepoint]['sCommityListApi'],
                        listObj: listObj,
                        newid: options.id
                    })
                    _this.getList();
                }
            }else {
                wx.$gcs_showToast("不存在的页面标识");
            }
        } else {
            wx.$gcs_showToast("缺少页面标识");
        }
    },
    /**
     * 获取对应新闻信息
     */
    getList: function () {
        var _this = this;
        wx.$requestApi(_this.data.listApi, _this.data.listObj, function (res) {
            if (res.code == 0) {
                var listObj = _this.data.listObj;
                listObj.iPages = res.iPages;
                _this.setData({
                    listData: _this.data.listData.concat(res.aData),
                    listObj: listObj
                })
            }else{
                wx.$gcs_showToast(res.msg);
            }
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var _this = this;
        console.log(_this.data.iPage, _this.data.iPages);
        var listObj = _this.data.listObj;
        if (listObj.iPage < listObj.iPages) {
            listObj.iPage++;
            _this.setData({
                listObj: listObj
            })
            _this.getList();
        }
    }
})